<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../common/admin.asp"-->
<%

PackageFalg=request.QueryString("PackageFalg")

if PackageFalg<>"" then
  set rss=conn.execute("select * from PackageOrder where [order]='"&PackageFalg&"'")
  if not rss.eof then
	InterTransCostx=rss("InterTransType")
	weight=rss("weight")
  set rss=nothing
  end if


  '计算运费
	  set rsne=server.CreateObject("adodb.recordset")
	  sql="select title from InterTransCost where id="&InterTransCostx&""
	  rsne.open sql,conn,1,3
	  if not rsne.eof then
		InterTransTitle=rsne("title")
	  rsne.close
	  set rsne=nothing
	  end if

end if










select case request.QueryString("mark")
case 1: title="已付款" : sqlsearch=" and Flag=1"
case 2: title="已寄出" : sqlsearch=" and Flag=2"
case 3: title="已签收" : sqlsearch=" and Flag=3"
case 4: title="有问题包裹" : sqlsearch=" and Flag=4"
end select


key=request.QueryString("key")
uid=request.QueryString("uid")
mark=request.QueryString("mark")
pay=request.QueryString("pay")
search=request.QueryString("search")
if search="搜索" then
	  if key<>"" then
			sqlsearch=sqlsearch+" and ([order] like '%"&key&"%')"
	  end if
	  if uid<>"" then
			sqlsearch=sqlsearch+" and (uid = '"&uid&"')"
	  end if
end if

'分页-------------------------------------------------------
set Rs=server.CreateObject("ADODB.RecordSet")
sql="select count(sortid) from (Select ROW_NUMBER() OVER (order by addtime desc,[order] desc ) as sortid,* From PackageOrder) as TempTable where 1=1 "&sqlsearch&""
Pager_Pagesize=10 '每页记录数
Rs.open sql,conn,1,1
Pager_TotalRecord=Rs(0) '总记录数
Rs.close
Pager_PageCount=int((Pager_TotalRecord/Pager_Pagesize)+0.99999) '计算总页数
CurrentPage=Request("page") '当前页
'如果不为数字则直接设置页码为1
if isnumeric(CurrentPage)=False Or CurrentPage="" then
	CurrentPage=1
'如果当前页数大于总页数，则直接设置页码为1
elseif  Clng(CurrentPage)>Pager_PageCount then
	CurrentPage=1
end if
Fieldsname=" [Id],[Uid],[order],[Oid],[Rate],[InterTransType],[InterTransCost],[PackageType],[PackageCost],[IsUsedSafety],[SafetyCost],[usedPoint],[SaveCost],[TransCost],[TrackingNumber],[Location],[CodeZip],[TEL],[Name],[Flag],[Addtime],[content],[weight],sortid"
orderBy=" Order by sortid asc"
'拆分SQL语句，必须是select开头，有唯一标识的列
if instr("select",sql)<>-1 then
	if CurrentPage = 1 then
		sql = replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize  & Fieldsname)
	else  
		sql = replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize   & Fieldsname) & " and sortid >(select max(sortid) from (" & replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize * (CurrentPage - 1)  & Fieldsname) & orderBy & ") AA)"
	end if
end if
sql = sql & orderBy
Rs.open sql,conn,1,1
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>main</title>
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
<style>body {background-color: #eaece1;}</style>
</head>

<body>
<div class="main">
  <div class="main-title">查看</div>
  <div class="main-content">
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <tr>
    <td colspan="6" align="center">
    <form name="form" method="get" action="">
    包裹编号 <input name="key" type="text" id="key" value="<%=key%>" maxlength="50" />
    买家 <input name="uid" type="text" value="<%=uid%>" maxlength="50" />
    <input name="mark" type="hidden" value="<%=mark%>" maxlength="50" />
    <input type="submit" name="search" value="搜索" />
    </form>
    </td>
    </tr>
    </table>
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <form action="" method="post">
  <tr>
    <td align="center" bgcolor="#FFFFFF"><strong>选择</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong><span class="items">订单号</span></strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong><span class="items">会员</span></strong></td>
    <td align="center" bgcolor="#FFFFFF">运输方式</td>
    <td align="center" bgcolor="#FFFFFF"><strong>重量</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>付款金额</strong></td>
    <td align="center" bgcolor="#FFFFFF">是否加入保险</td>
    <td align="center" bgcolor="#FFFFFF">包装方式</td>
    <td bgcolor="#FFFFFF"><strong>付款时间</strong></td>
    </tr>
    <%do while not Rs.eof%>
  <tr>
    <td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="checkbox" id="checkbox" value="<%=rs("order")%>" <%if rs("Flag")="3" then response.Write " disabled "%>/><input type="hidden" name="wid" value="<%=rs("order")%>" /></td>
    <td align="center" bgcolor="#FFFFFF"><a href="add.asp?id=<%=rs("order")%>"><%=rs("order")%></a></td>
    <td align="center" bgcolor="#FFFFFF"><a href="../user/edit.asp?id=<%=rs("uid")%>"><%=rs("uid")%></a></td>
    <td align="center" bgcolor="#FFFFFF">
    <%set rss=conn.execute("select title from InterTransCost where id="&rs("InterTransType"))
					 if not rss.eof then
					 response.write rss("title")
					 end if
					 set rss=nothing%>
    </td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("weight")%></td>
    <td align="center" bgcolor="#FFFFFF">
    
    <%=(CDBL(RS("TransCost"))+CDBL(RS("InterTransCost"))+CDBL(RS("PackageCost")))*cdbl(rs("Rate"))%>
    
    </td>
    <td align="center" bgcolor="#FFFFFF"><%IF RS("IsUsedSafety")=true then response.Write "是" else response.Write "否"%></td>
    <td align="center" bgcolor="#FFFFFF">
      
      <%set rss=conn.execute("select title from PackageCost where id="&rs("PackageType"))
								 if not rss.eof then
								 response.write rss("title")
								 end if
								 set rss=nothing%>
    </td>
    <td bgcolor="#FFFFFF"><%=rs("addtime")%> <%if mark="1" then response.Write "&nbsp; &nbsp; <a href='?mark=1&PackageFalg="&rs("order")&"'>发货</a>"%></td>
    </tr>
    <%
	Rs.movenext
	loop
	Rs.close
	Set Rs=nothing
	%>
    <tr>
      <td colspan="9" align="center" bgcolor="#FFFFFF" class="page">
      
      <%
			select case request.QueryString("mark")
	  case 1: response.Write "已付款   <input type=""submit"" name=""button"" value=""问题包裹"">"
	  case 2: response.Write "已寄出  <input type=""submit"" name=""button"" value=""已签收"">"
	  case 4: response.Write "问题包裹   <input type=""submit"" name=""button"" value=""已寄出"">"
	  end select
	  %>
      
      
      
      </td>
    </tr>
    </form>
    <tr>
    <td colspan="9" align="center" bgcolor="#FFFFFF" class="page">　
      <%
	siteurl=request.servervariables("document_name")
	%>
    <form action="<%=siteurl%>" method="get">
    共 <%=Pager_TotalRecord%> 条 第<%=CurrentPage%>页 / 共 <%=Pager_PageCount%> 页
		<%
		pageurl="key="&key&"&pay="&pay&"&uid="&uid&"&mark="&mark&"&search="&search&"&"
		if CurrentPage=1 then
			response.Write(" 首页 ")
			response.Write(" 上一页 ")
		else
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page=1'>首页</a> ")
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& (CurrentPage-1) &"'>上一页</a> ")
		end if
		%>
		<%
		if Clng(CurrentPage)=Clng(Pager_PageCount) then
			response.Write(" 下一页 ")
			response.Write(" 尾页 ")
		else
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& (CurrentPage+1) &"'>下一页</a> ")
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& Pager_PageCount &"'>尾页</a> ")
		end if
		%>
		&nbsp;
		<input name="page" type="text" value="<%=CurrentPage%>" size="1" maxlength="10" />
        <input type="submit" name="button" value="跳转" />
        <input type="hidden" name="key" value="<%=key%>" />
        <input type="hidden" name="uid" value="<%=uid%>" />
        <input type="hidden" name="mark" value="<%=mark%>" />
        <input type="hidden" name="pay" value="<%=pay%>" />
        <input type="hidden" name="search" value="搜索" />
        </form>
      </td>
    </tr>
  </table>
</div>
</div>



<%if PackageFalg<>"" then%>
<div class="pop_contentx">
<h2><a href = "order.asp?mark=1">关闭</a>发货登记</h2>
<ul>
  <table width="80%" border="0" cellspacing="0" cellpadding="4">
  <form name="formcn" method="post" action="" onSubmit="return myjobchk();">
    <tr>
      <td>包裹编号</td>
      <td><%=request.QueryString("PackageFalg")%></td>
    </tr>
    <tr>
      <td>重量</td>
      <td><input name="weight2" type="text" value="<%=weight%>" maxlength="10" />
        克</td>
    </tr>
    <tr>
      <td>运输方式</td>
      <td><input name="InterTransType2" type="text" value="<%=InterTransTitle%>" maxlength="10" /></td>
    </tr>
    <tr>
      <td>实付运费</td>
      <td><input name="InterTransCost2" type="text" value="" maxlength="10" /></td>
    </tr>
    <tr>
      <td>运单号</td>
      <td><input name="TrackingNumber" type="text" value="" maxlength="10" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="r" id="button" value="提交" />
      <input type="hidden" name="B" value="YES" />
      <input type="hidden" name="PackageFalg" value="<%=PackageFalg%>" />
      </td>
    </tr>
    </form>
  </table>
</ul>
</div> 
<div class="pop_bgx"></div> 
<%end if%>





</body>
</html>
<%

IF request.Form("B")="YES" then
conn.execute("update PackageOrder set Flag=2,weight2="&request.Form("weight2")&",InterTransType2='"&request.Form("InterTransType2")&"',InterTransCost2='"&request.Form("InterTransCost2")&"',TrackingNumber='"&request.Form("TrackingNumber")&"' where [order] = '"&request.Form("PackageFalg")&"'")
response.Redirect "order.asp?mark="&mark&"&page="&request.QueryString("page")&""
end if


wid=request.Form("wid")
if wid<>"" then
   if request.Form("button")="保存运单号" then
     wid=split(replace(wid," ",""),",")
     for i=0 to ubound(wid)
	 conn.execute("update packageOrderList set WaybillNumber='"&request.Form("WaybillNumber"&wid(i))&"' where [order] = '"&wid(i)&"'")
	 next
	 response.Redirect "order.asp?mark="&mark&"&page="&request.QueryString("page")&""
   end if
end if




checkbox=request.Form("checkbox")
if checkbox<>"" then	
	if request.Form("button")="取消" then
		moneyuser=split(replace(checkbox," ",""),",")
        for f=0 to ubound(moneyuser)
		  set rss=server.CreateObject("adodb.recordset")
		  sql="select * from PackageOrderDetail where [order]='"&moneyuser(f)&"'"
		  rss.open sql,conn,1,3
		  if not rss.eof then
		  do while not rss.eof 
              if rss("typeid")="0" then
              conn.execute("update auctions set mark=5 where mark=6 and id="&rss("oid")&"")
			  else
              conn.execute("update OrderDetail set mark=5 where mark=6 and id="&rss("oid")&"")
              end if
		  rss.movenext
		  loop
		  rss.close
		  set rss=nothing
		  end if  
		next

		conn.execute("update packageOrderList set mark=0 where [order] in ("&checkbox&")")

	elseif request.Form("button")="已付款" then
		conn.execute("update packageOrderList set mark=2,rate='"&web_rate&"' where [order] in ("&checkbox&")")
	
	elseif request.Form("button")="问题包裹" then
		conn.execute("update PackageOrder set Flag=4 where [order] in ("&checkbox&")")
	
	elseif request.Form("button")="装箱中" then
		conn.execute("update packageOrderList set mark=4 where [order] in ("&checkbox&")")
	
	elseif request.Form("button")="等待邮寄" then
		conn.execute("update packageOrderList set mark=5 where [order] in ("&checkbox&")")
	
	elseif request.Form("button")="已寄出" then
		conn.execute("update PackageOrder set Flag=2 where [order] in ("&checkbox&")")
	
	elseif request.Form("button")="已签收" then
		conn.execute("update PackageOrder set Flag=3 where [order] in ("&checkbox&")")
	end if
	
	response.Redirect "order.asp?mark="&mark&"&page="&request.QueryString("page")&""
end if
%>